﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;

public class Program
{
    private static int Main(string[] args)
    {
        string settingPath = AppDomain.CurrentDomain.BaseDirectory + "setting.config";
        if (!File.Exists(Path.GetFullPath(settingPath)))
        {
            Console.WriteLine("配置文件不存在");
            Console.ReadLine();
            return 1;
        }

        XmlDocument xmlDocument = new XmlDocument();
        xmlDocument.Load(settingPath);
        XmlElement documentElement = xmlDocument.DocumentElement;
        string inputPath = Path.GetFullPath(documentElement.GetElementsByTagName("inputPath")[0].InnerText);
        string outputPath = Path.GetFullPath(documentElement.GetElementsByTagName("outputPath")[0].InnerText);
        string fileType = documentElement.GetElementsByTagName("fileType")[0].InnerText;
        if (!Directory.Exists(inputPath))
        {
            Console.WriteLine("输入路径不存在");
            Console.ReadLine();
            return 2;
        }
        if (fileType == "" || fileType == null)
        {
            Console.WriteLine("标签fileType不存在");
            Console.ReadLine();
            return 4;
        }
        string[] types = fileType.Split(',');
        List<string> typeL = new List<string>();
        for (int i = 0; i < types.Length; i++)
        {
            typeL.Add(types[i]);
        }
        if (typeL.Count == 0)
        {
            Console.WriteLine("要压缩文件类型是空");
            Console.ReadLine();
            return 5;
        }
        List<string> packList = new List<string>();
        string[] files = Directory.GetFiles(inputPath);
        foreach (string file in files)
        {
            if (types.Contains(Path.GetExtension(file)))
            {
                packList.Add(file);
            }
        }
        if (packList.Count == 0)
        {
            Console.WriteLine("未找到打包的文件");
            Console.ReadLine();
            return 3;
        }
        List<string> zipFileNames = new List<string>();
        List<byte[]> zipFileDatas = new List<byte[]>();
        foreach (string file2 in packList)
        {
            zipFileNames.Add(Path.GetFileName(file2));
            zipFileDatas.Add(File.ReadAllBytes(file2));
        }
        ZipUtil.CompressFileList(Path.GetFullPath(outputPath), zipFileNames, zipFileDatas);
        Console.WriteLine("456456");
        Console.ReadLine();
        return 0;
    }
}
